﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using libCommonTools.Forms;
using libCommonTools.BUS;
using libAddressBook.BUS;
using libDAL;

namespace libAddressBook.FORMS
{
    public partial class frmWebsiteEmailFax : Telerik.WinControls.UI.RadForm
    {

        private string strType = string.Empty;

        private cls_DAL _DAL;
        private clsInterfaceWebsiteEmailContactFax Contacts;
        private string strCompanyID = string.Empty;

        public string getset_CompanyID
        {
            get
            {
                return strCompanyID;
            }
            set
            {
                strCompanyID = value;
            }
        }

        public cls_DAL set_DataAccess
        {
            set
            {
                _DAL = value;
            }
        }

        public string getset_Type
        {
            get
            {
                return this.strType;
            }
            set
            {
                this.strType = value;
            }
        }

        public frmWebsiteEmailFax()
        {
            InitializeComponent();
        }

        private void frmWebsiteEmailFax_Load(object sender, EventArgs e)
        {
            try
            {
                this.Size = new Size(601, 386);
                Contacts = new clsInterfaceWebsiteEmailContactFax();
                Contacts.set_DataAccess = _DAL;
                Contacts.set_CompanyID = getset_CompanyID;
                set_DataGrid();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " frmWebsiteEmailFax_Load"); 
            }
        }

        private void set_CheckGridColumns()
        {
            if (dgvContacts.Columns.Count > 0)
            {
                dgvContacts.Columns.Clear();
            }
        }

        private void set_loadGridContactPerson()
        {
            try
            {

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_loadGridContactPerson"); 
            }
        }

        private void set_GridColumnsContact()
        {
            try
            {
                set_CheckGridColumns();
                dgvContacts.Columns.Add("AddressBookContactPersonID", "ddressBookContactPersonID");
                dgvContacts.Columns["AddressBookContactPersonID"].IsVisible = false;

                dgvContacts.Columns.Add("comid", "comid");
                dgvContacts.Columns["comid"].IsVisible = false;

                dgvContacts.Columns.Add("AddressBookContactPerson", "Contact Person");
                dgvContacts.Columns["AddressBookContactPerson"].IsVisible = true;

                dgvContacts.Columns.Add("AddressBookContactNumberMobile", "Mobile No.");
                dgvContacts.Columns["AddressBookContactNumberMobile"].IsVisible = true;

                dgvContacts.Columns.Add("AddressBookContactNumberLandLinePre", "Area Code");
                dgvContacts.Columns["AddressBookContactNumberLandLinePre"].IsVisible = true;
                
                dgvContacts.Columns.Add("AddressBookContactNumberLandLine", "Land Line No.");
                dgvContacts.Columns["AddressBookContactNumberLandLine"].IsVisible = true;

                dgvContacts.Columns.Add("AddressBookContactDefault", "Default");
                dgvContacts.Columns["AddressBookContactDefault"].IsVisible = true;
                dgvContacts.Columns["AddressBookContactDefault"].ReadOnly = true;

                dgvContacts.Columns.Add("AddressBookContactICCPassport", "ICC/Passport");
                dgvContacts.Columns["AddressBookContactICCPassport"].IsVisible = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GridColumnsContact"); 
            }
        }

        private void set_LoadGridRecords()
        {
            dgvContacts.DataSource = Contacts.get_ContactPerson;
            dgvContacts.Columns[0].IsVisible = false;
            dgvContacts.Columns[1].IsVisible = false;
            dgvContacts.Columns["Dfault"].ReadOnly = true;
        }

        private void set_DataGrid()
        {
            try
            {
                if (getset_Type != string.Empty)
                {
                    if (getset_Type == "Contacts")
                    {
                        Contacts.getset_ContactType = getset_Type;
                        Contacts.set_CompanyID = getset_CompanyID;
                        set_LoadGridRecords();
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_DataGrid"); 
            }
        }

        private void cbbReFreshContacts_Click(object sender, EventArgs e)
        {
            chkDefault.Checked = false;
            rboEdit.IsChecked = false;
            rboNew.IsChecked = false;
        }

        private void btnApply_Click(object sender, EventArgs e)
        {

        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void dgvContacts_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            try
            {
                if (dgvContacts.CurrentColumn.Name == "Dfault")
                {
                    MessageBox.Show(dgvContacts.CurrentRow.Cells["Dfault"].Value.ToString() + " yy");
                }

                //for (int intRow = 0; intRow < dgvContacts.Rows.Count; intRow++)
                //{
                //    if (dgvContacts.Rows[intRow].IsSelected == false)
                //    {
                //        dgvContacts.Rows[intRow].Cells["Dfault"].Value = false;
                //    }
                //    else
                //    {
                //        dgvContacts.Rows[intRow].Cells["Dfault"].Value = true;
                //    }
                //}

               

                //Dfault


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " dgvContacts_CellValueChanged"); 
            }
        }

        private void dgvContacts_ValueChanged(object sender, EventArgs e)
        {
            //if (dgvContacts.CurrentColumn.Name == "Dfault")
            //{
            //    for (int intRow = 0; intRow < dgvContacts.Rows.Count; intRow++)
            //    {
                 //   MessageBox.Show(dgvContacts.Rows[intRow].Cells["Dfault"].Value.ToString());
                 //   MessageBox.Show(dgvContacts.CurrentRow.Cells["Dfault"].Value.ToString()); 
               // }
          //  }

            if (dgvContacts.CurrentColumn.Name == "Dfault")
            {
                MessageBox.Show(dgvContacts.CurrentRow.Cells["Dfault"].Value.ToString() + "xx");
            }
        }

        private void dgvContacts_CreateRowInfo(object sender, Telerik.WinControls.UI.GridViewCreateRowInfoEventArgs e)
        {
            MessageBox.Show(e.ViewInfo.ToString()); 
        }
    }
}
